define(['jquery', 'bootstrap', 'backend', 'table', 'form','untils'], function ($, undefined, Backend, Table, Form,Untils) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'seckill/kill/index' + location.search,
                    add_url: 'seckill/kill/add',
                    edit_url: 'seckill/kill/edit',
                    del_url: 'seckill/kill/del',
                    multi_url: 'seckill/kill/multi',
                    table: 'kill',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showToggle: false,
                showColumns: false,
                showExport: false,
                columns: [
                    [
                        {checkbox: true},
                       /* {field: 'id', title: __('Id')},
                        {field: 'year', title: __('Year')},
                        {field: 'month', title: __('Month')},
                        {field: 'day', title: __('Day')},
                        {field: 'goods_ids', title: __('Goods_ids')},
                        {field: 'price', title: __('Price')},
                        {field: 'stock', title: __('Stock')},
                        {field: 'time_id', title: __('Time_id')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'goods.id', title: __('Goods.id')},
                        {field: 'goods.name', title: __('Goods.name')},
                        {field: 'goods.images', title: __('Goods.images'), events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'goods.stock', title: __('Goods.stock')},
                        {field: 'goods.createtime', title: __('Goods.createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'activity.id', title: __('Activity.id')},
                        {field: 'activity.name', title: __('Activity.name')},
                        {field: 'activity.times', title: __('Activity.times')},
                        {field: 'activity.closesec', title: __('Activity.closesec')},
                        {field: 'activity.status', title: __('Activity.status'), formatter: Table.api.formatter.status},
                        {field: 'activity.createtime', title: __('Activity.createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},*/
                        {field: 'id', title: __('Id')},
                        {field: 'year', title: __('Year')},
                        {field: 'month', title: __('Month')},
                        {field: 'day', title: __('Day')},
                        {field: 'goods_ids', title: __('Goods_ids')},
                        {field: 'goods.name', title: __('Goods.name')},

                        {field: 'time_id', title: __('Time_id')},
                        {field: 'activity.name', title: __('Activity.name')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();

            $('#month').change(function () {
                var year = $('#year').val();
                var month = $(this).val();
                untils.request({
                    url:"/admin/seckill/Kill/getMonthLastDays",
                    data:{year,month}
                }).then(function (res) {
                    console.log('res:',res);


                    var html = res.data.html;

                    $('.choose').siblings().remove();

                    /*var html = '';
                    for(var i=1;i<=days;i++){
                        html += '<tr>';
                        html +=  '<td><input id="c-day" data-rule="required" class="form-control" name="row[day][]" type="text" value="'+i+'" readonly> </td>'
                        html +=  '<td><input id="c-time_id"  data-source="/admin/seckill/activity/index" data-field="name" class="form-control selectpage" name="row[time_id]" type="text" value=""></td>'
                        html += '<td><input id="c-goods_ids" data-source="/admin/seckill/goods/index" data-field="name" data-multiple="true" class="form-control selectpage" name="row[goods_ids][]" type="text" value=""> </td>';
                        html += '</tr>';
                    }*/

                    $('.choose').after(html);
                }).catch(function (err) {
                    layer.msg(err.msg);
                })
            })


        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
            
        }
    };
    return Controller;
});